import { message } from 'antd';
import * as api from '../utils/api';

const MESSAGEERROR = message.error
export default {

    namespace: 'personal',

    state: {
        dataSource: [],
        current:1,
        totalPage:0,
        columns : [
            {
                title: 'id',
                dataIndex: 'id',
                key: 'id',
                align:'center'
            },
            {
                title: '姓名',
                dataIndex: 'name',
                key: 'name',
                align:'center'
            },
            {
                title: '年龄',
                dataIndex: 'age',
                key: 'age',
                align:'center'
            },
            {
                title: '邮箱',
                dataIndex: 'mailbox',
                key: 'mailbox',
                align:'center'
            },
            {
                title: '操作',
                key: 'action',
                align:'center',
                render: () => <a>Delete</a>
            },
        ]
    },
    effects: {
        *getDataSource({ payload }, { call, put }) {
            const res = yield call(api.getPersonalTable, payload);
            console.log(res)
            if (res.code === 0) {
                yield put({
                    type: 'updateDataSource',
                    action: Object.assign(res.data,payload.data)
                })
            } else {
                MESSAGEERROR('(︶︿︶)' + res.msg)
            }
        }
    },
    reducers: {
        'updateDataSource'(state, { action: data }) {
            let newState = Object.assign({}, state)
            newState.dataSource = data.list
            newState.totalPage = data.totalPage
            newState.currPage = data.currPage
            return newState
        },
    },
};
